#coding=utf-8
from flask import Flask, current_app
from flaskext.script import Server, Shell, Manager, Command, prompt_bool
from apscheduler.scheduler import Scheduler
from sys2do import app
from sys2do.model import db
sched = Scheduler()
sched.start()

#crontab to update front-site news
#@sched.cron_schedule(minute='0')
def postNews():
    import urllib
    cnt = urllib.urlopen('http://www.chowahfook.com/wp-content/themes/chowahfook/cron_search_news.php').read()
    from datetime import datetime as dt
    print '~!'*40
    print cnt
    print dt.now()

def make_shell_context():
    return dict(app=app)

#app = create_app('config.py')
manager = Manager(app)
manager.add_command("runserver", Server('192.168.20.53', port=5000))
manager.add_command("shell", Shell(make_context=make_shell_context))

@manager.command
def createall():
    db.create_all()

@manager.command
def dropall():
    if prompt_bool("Are you sure ? You will lose all your data !"):
        db.drop_all()

if __name__=='__main__':
    manager.run()
